﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//Sortierungen
//Lieferanten Neu erstellt      ->  1000 
//Lieferant geändert            ->  1001
//Lieferant gelöscht            ->  1002
//Flaschenfüllung abgeschlossen ->  2001
//Flaschenfüllung abgerechnet   ->  2002 
//Systemmeldung                 ->  3000 
//Login am System               ->  3001
//Logoff am System              ->  3002

namespace DiveManager
{
    public partial class LiveReportingMain : Form
    {
        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        public String updatearea;

        int timercounter = 0;
        
        public LiveReportingMain()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label3.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label4.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label5.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label6.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label7.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label8.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label9.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label10.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label11.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label12.BackColor = System.Drawing.SystemColors.ControlDark;
            timercounter ++;

            if (timercounter == 1)
            {
                
                this.label3.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 2)
            {
                
                this.label4.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 3)
            {
                
                this.label5.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 4)
            {
                
                this.label6.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 5)
            {
                
                this.label7.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 6)
            {
                
                this.label8.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 7)
            {
                
                this.label9.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 8)
            {
                
                this.label10.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 9)
            {
                
                this.label11.BackColor = System.Drawing.Color.Green;
            }
            if (timercounter == 10)
            {
                
                this.label12.BackColor = System.Drawing.Color.Green;
                timercounter = 0;
                //Update des in der Liste ausgewählten Reports
                EventAuswahl();


            }



            
        }

        private void LiveReportingMain_Load(object sender, EventArgs e)
        {
            
        }

        private void btAutoUpdateOn_Click(object sender, EventArgs e)
        {
            timercounter = 0;
            btUpdate.Visible = false;
            btAutoUpdateOff.Visible = true;
            btAutoUpdateOn.Visible = false;
            timer1.Start();
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            //Update des in der Liste ausgewählten Reports
            EventAuswahl();
        }

        private void btAutoUpdateOff_Click(object sender, EventArgs e)
        {
            btAutoUpdateOff.Visible = false;
            btUpdate.Visible = true;
            btAutoUpdateOn.Visible = true;
            timer1.Stop();
            this.label3.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label4.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label5.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label6.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label7.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label8.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label9.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label10.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label11.BackColor = System.Drawing.SystemColors.ControlDark;
            this.label12.BackColor = System.Drawing.SystemColors.ControlDark;
        }

        private void btShow_Click(object sender, EventArgs e)
        {
            //Anzeigen des in der Liste ausgewählten Reports
            TreeNode node = treeView1.SelectedNode;
            updatearea = node.Text;
            btAutoUpdateOn.Visible = true;
            btUpdate.Visible = true;
            if (node.Text.Equals(""))
            {
                MessageBox.Show("Keine Auswahl getroffen");
            }
            else
            {
                EventAuswahl();
            }

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        protected void EventAuswahl()
        {
            
            if (updatearea.Equals("Lieferant Neu Erstellt"))
            {
                //Abfrage aller neu erstellen Lieferanten -> letzte 25 Einträge
                LoadData1();
            }

            if (updatearea.Equals("Lieferant geändert"))
            {
                //Abfrage aller geänderten Lieferanten -> letzte 25 Einträge
                LoadData2();
            }

            if (updatearea.Equals("Lieferant gesamt"))
            {
                //Abfrage aller gelöschten Lieferanten -> letzte 25 Einträge
                LoadData3();
            }
            if (updatearea.Equals("Füllungen Gesamt"))
            {
                //Abfrage aller Flaschenfüllungen -> letzte 25 Einträge
                LoadData_FuellungenGesamt();
            }
            if (updatearea.Equals("Füllungen abgeschlossen"))
            {
                //Abfrage aller abgeschlossenen Füllungen -> letzte 25 Einträge
                LoadData_FuellungenAbgeschlossen();
            }
            if (updatearea.Equals("Füllungen abgerechnet"))
            {
                //Abfrage aller gelöschten Lieferanten -> letzte 25 Einträge
                LoadData_FuellungenAbgerechnet();
            }
            if (updatearea.Equals("Gesamtansicht"))
            {
                //Alle Reportbereiche -> letzte 25 Einträge
                LoadData_AllReport();
            }
            if (updatearea.Equals("Rechnungs Warteschleife"))
            {
                //Alle Reportbereiche -> letzte 25 Einträge
                LoadData_ReWarteschleife();
            }
            if (updatearea.Equals("Systemmeldungen"))
            {
                //Alle Systemmeldungen -> letzte 25 Einträge
                LoadData_Systemmeldungen();
            }
            if (updatearea.Equals("Login am System"))
            {
                //Alle Systemmeldungen -> letzte 25 Einträge
                LoadData_LoginSystem();
            }
            if (updatearea.Equals("Logoff am System"))
            {
                //Alle Systemmeldungen -> letzte 25 Einträge
                LoadData_LogoffSystem();
            }

        }


        protected void LoadData1()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung==1000
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData2()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 1001
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData3()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where (a.Sortierung == 1000) || (a.Sortierung == 1001)
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_FuellungenGesamt()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where (a.Sortierung == 2001) || (a.Sortierung == 2002)
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_FuellungenAbgeschlossen()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 2001 
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_FuellungenAbgerechnet()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 2002
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_AllReport()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_ReWarteschleife()
        {
            IQueryable<RechnungWarteschleife> dataQuery = (from a in diveDatabase.RechnungWarteschleife
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Bezeichnung"].Visible = true;
            ReportList.Columns["Beschreibung"].Visible = true;
            ReportList.Columns["KDNR"].Visible = true;
            ReportList.Columns["Menge"].Visible = true;
            ReportList.Columns["Gesamtpreis"].Visible = true;
            ReportList.Columns["Date"].Visible = false;
            ReportList.Columns["User"].Visible = false;
            ReportList.Columns["Preis"].Visible = false;
        }

        protected void LoadData_Systemmeldungen()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 3000
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_LoginSystem()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 3001
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }

        protected void LoadData_LogoffSystem()
        {
            IQueryable<ReportingMain> dataQuery = (from a in diveDatabase.ReportingMain
                                                   where a.Sortierung == 3002
                                                   select a);
            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;
            // Bind BindingSource to List
            ReportList.DataSource = bindingSource;
            // Hide ID-Columns
            ReportList.Columns["ID"].Visible = false;
            ReportList.Columns["Report_Text"].Visible = true;
            ReportList.Columns["Sortierung"].Visible = false;
            ReportList.Columns["Objekt"].Visible = true;
            ReportList.Columns["Date"].Visible = true;
            // Set Column Headers
            ReportList.Columns["Report_Text"].HeaderText = "Meldung";
            ReportList.Columns["Objekt"].HeaderText = "Objekt";
            ReportList.Columns["Date"].HeaderText = "Auftreten";
        }
    }
}
